#include "Utils.h"


void Utils::Strip(string& str) {
	int count = 0;
	for(int i = 0; i < str.length(); ++i) {
		if (str[i] == ' ' || str[i] == '\n' || str[i] == '\r') {
			count += 1;
		} else {
			break;
		}
	}

	if (count > 0) {
		str.erase(str.begin(), str.begin() + count);
	}


	count = 0;
	for(int j = str.length() - 1; j > 0; --j) {
		if (str[j] == ' ' || str[j] == '\r' || str[j] == '\n') {
			count += 1;
		} else {
			break;
		}
	}

	if (count > 0) {
		str.erase(str.end() - count, str.end());
	}

}


vector<string> Utils::Split(const string str, const char ch) {
	vector<string> ret;

	int previous = 0;
	for(int i = 0; i < str.length(); ++i) {
		if (str[i] == ch) {
			ret.push_back(str.substr(previous, i - previous));
			previous = i + 1;
		}
		if (i == str.length()-1) {
			ret.push_back(str.substr(previous));
		}
	}	


	return ret;
}
